<?php

namespace paymch\modules\test\controllers;

use Yii;
use yii\web\Controller;

/**
 * Default controller for the `test` module
 */
class DefaultController extends Controller {

    /**
     * Renders the index view for the module
     * @return string
     */
    public function actionIndex() {
        return $this->render('index');
    }

    /**
     * actionRefund
     * Description
     *
     * @view template.php
     * @return mixed
     */
    public function actionRefund() {
        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

        $aop = new \paymch\components\alipay\aop\AopClient ();
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->appId = Yii::$app->params['alipay']['appid'];
        $aop->rsaPrivateKey = 'MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQD0O4X7hUgrmT7J+4rCV1Rb/86l+dNIzua4HRQbZm+pwDEmgoKEwz6UUp2TMR1tKZuxQtDZqZH495SoqsAkar8vOMri4MrFS0lmHH6iyYIMIGSzPZEqMJRffzCutXoCJUWD++fYUyn2cRn+esic1+/Fh6uzo1B5nznF6ThQ75ubzX+S0p8WnHUeBlBwQ+nOe4krjVDu2a1aoCc9c8YgTKZtDlAqlSljqbG3kPZNEASoxov2Wzh7xYpuQNDXgOAmnwNDoWkdqiNI+SWOc05tBJi5WVnGtqPkzbdQKsP13lkw4Eu9W+D14RdFVjdD2jmM+9z+b0BsI0aZ0+7AcKyt2x43AgMBAAECggEAEQEv8/I0syxpTcDgyWUxL3KhHbdGObSGJd2Ib9vy/FuwUGEX20yIx+T0qbHqvZX/DBl91xnSWwZJ6HBzDlYMV6pZnfBOzevPAXgMbSMgld2PhVdNCyX0vq1pY1CpXQrhSy431zz7F/iJ+cjsvNbgD93BW7GMQduPNzNkw2XbbL6ASJuiresgdkGZIZtLoSKaIzojGJELBeSPWME1ODWdxkxd05og6U3I/FQH0ElTIVZ4j0BptWJsfKGtT4gn6gZ+cfpdtI+jKWtCZcg8g4OCRFtcMDRAUAsEdCsLo+Mw7O9uITySnctptXeffhGMmbCVKIIX16qy/8xexdfjjUS0WQKBgQD6QMRDpAMjRIqlQY5yNIQQIJlHEGAQ+S4d6vur/N747do0ucUolNZprHtLUmmtfVb5jgPXbIrr4ueuS8YhbTBIuHN+dSQ/WHAJoRLDx7wGI3VTvUc6onfYL+uuA8jYadO5s4ITcVuB0GJWdGOA7HgmAUlOJkYIm5OIVgP5EjECdQKBgQD511zGEbgZY1Nrt8095ybryK4A2l8nLyTheJafsoBcbqUmC8XR0zfqLQa8hY3bJNaHCL4bVZNFHMJVBvZp/3ubJ8ZPtGXQlKut2ZfXzUiydbVQn25fT/M2v8bPiiI/vx5aAoSXBUcObC6Qiy77xPiy8b7AooRH5UPKUu+uU1UwewKBgQC88XN9gnKgCRsJBIMRNRdUudggcHuntQsdqZIU25pZpfOvBWeXaTCtnn2EdBe31j95scCywI/u42V7EljoWfEvppwEqVsRvKryijuJt979X34xGGKUIaCMiDnQK6lTxCsINUELfvXRAE2O6tdJusBIKYZ4S6tqylPMhuz++74nFQKBgQDSNZ6sVFpGmiilODeqvuMjfWzR8OogiO0J/DEXWtPfcYTolv0xRvsDwDCry98IJF2Prg5t5zmK6+CiM8J+euQgLn4Pr+P+dChilPLKMsHYzWrp08rEzPsA9KitFDcu1XoPF5FBk8IuY11mZoT4dskdnoL1h4evCjpYcCGT1i+WIwKBgQDroCMSy28ElypZQvp8ZagSqJHGy5i/KdklRmbfWT99IEtx8G9E/ptUpM98bECXIStpu+w1qhM/CMkvdBeW+E5PtVYIZmod8Xdy11XBiS2zIBjJHmZXR6Y1INjK02Yn69xu8WlD3o0PX9I7OrZw97MwXBuEMSSqOdmQ3ZUwWjWgpQ==';
        $aop->alipayrsaPublicKey = Yii::$app->params['alipay']['public'];
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset = 'UTF-8';
        $aop->format = 'json';
        $request = new \paymch\components\alipay\aop\request\AlipayTradeRefundRequest();

        $data = [
            "out_trade_no" => "2017102110290016",
            "trade_no" => "2017102121001004180227754995",
            "refund_amount" => 0.01,
            "refund_reason" => "正常测试部分退款",
            "out_request_no" => "HZ01RF004",
        ];
        $jsonstring = \yii\helpers\Json::encode($data);
        $request->setBizContent($jsonstring);
        return $result = $aop->execute($request);

        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        $resultCode = $result->$responseNode->code;
        if (!empty($resultCode) && $resultCode == 10000) {
            return "成功";
        } else {
            return "失败";
        }
    }

    /**
     * actionCreate
     * Description
     *
     * @view create.php
     * @return mixed
     */
    public function actionQuery() {
        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        $aop = new \paymch\components\alipay\aop\AopClient();
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->appId = Yii::$app->params['alipay']['appid'];
        $aop->rsaPrivateKey = 'MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQD0O4X7hUgrmT7J+4rCV1Rb/86l+dNIzua4HRQbZm+pwDEmgoKEwz6UUp2TMR1tKZuxQtDZqZH495SoqsAkar8vOMri4MrFS0lmHH6iyYIMIGSzPZEqMJRffzCutXoCJUWD++fYUyn2cRn+esic1+/Fh6uzo1B5nznF6ThQ75ubzX+S0p8WnHUeBlBwQ+nOe4krjVDu2a1aoCc9c8YgTKZtDlAqlSljqbG3kPZNEASoxov2Wzh7xYpuQNDXgOAmnwNDoWkdqiNI+SWOc05tBJi5WVnGtqPkzbdQKsP13lkw4Eu9W+D14RdFVjdD2jmM+9z+b0BsI0aZ0+7AcKyt2x43AgMBAAECggEAEQEv8/I0syxpTcDgyWUxL3KhHbdGObSGJd2Ib9vy/FuwUGEX20yIx+T0qbHqvZX/DBl91xnSWwZJ6HBzDlYMV6pZnfBOzevPAXgMbSMgld2PhVdNCyX0vq1pY1CpXQrhSy431zz7F/iJ+cjsvNbgD93BW7GMQduPNzNkw2XbbL6ASJuiresgdkGZIZtLoSKaIzojGJELBeSPWME1ODWdxkxd05og6U3I/FQH0ElTIVZ4j0BptWJsfKGtT4gn6gZ+cfpdtI+jKWtCZcg8g4OCRFtcMDRAUAsEdCsLo+Mw7O9uITySnctptXeffhGMmbCVKIIX16qy/8xexdfjjUS0WQKBgQD6QMRDpAMjRIqlQY5yNIQQIJlHEGAQ+S4d6vur/N747do0ucUolNZprHtLUmmtfVb5jgPXbIrr4ueuS8YhbTBIuHN+dSQ/WHAJoRLDx7wGI3VTvUc6onfYL+uuA8jYadO5s4ITcVuB0GJWdGOA7HgmAUlOJkYIm5OIVgP5EjECdQKBgQD511zGEbgZY1Nrt8095ybryK4A2l8nLyTheJafsoBcbqUmC8XR0zfqLQa8hY3bJNaHCL4bVZNFHMJVBvZp/3ubJ8ZPtGXQlKut2ZfXzUiydbVQn25fT/M2v8bPiiI/vx5aAoSXBUcObC6Qiy77xPiy8b7AooRH5UPKUu+uU1UwewKBgQC88XN9gnKgCRsJBIMRNRdUudggcHuntQsdqZIU25pZpfOvBWeXaTCtnn2EdBe31j95scCywI/u42V7EljoWfEvppwEqVsRvKryijuJt979X34xGGKUIaCMiDnQK6lTxCsINUELfvXRAE2O6tdJusBIKYZ4S6tqylPMhuz++74nFQKBgQDSNZ6sVFpGmiilODeqvuMjfWzR8OogiO0J/DEXWtPfcYTolv0xRvsDwDCry98IJF2Prg5t5zmK6+CiM8J+euQgLn4Pr+P+dChilPLKMsHYzWrp08rEzPsA9KitFDcu1XoPF5FBk8IuY11mZoT4dskdnoL1h4evCjpYcCGT1i+WIwKBgQDroCMSy28ElypZQvp8ZagSqJHGy5i/KdklRmbfWT99IEtx8G9E/ptUpM98bECXIStpu+w1qhM/CMkvdBeW+E5PtVYIZmod8Xdy11XBiS2zIBjJHmZXR6Y1INjK02Yn69xu8WlD3o0PX9I7OrZw97MwXBuEMSSqOdmQ3ZUwWjWgpQ==';
        $aop->alipayrsaPublicKey = Yii::$app->params['alipay']['public'];
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset = 'UTF-8';
        $aop->format = 'json';
        $request = new \paymch\components\alipay\aop\request\AlipayTradeQueryRequest();
        $data = [
            "out_trade_no" => "2017102110290016",
            "trade_no" => "2017102121001004180227754995",
        ];
        $jsonstring = \yii\helpers\Json::encode($data);
        $request->setBizContent($jsonstring);
        return $result = $aop->execute($request);

        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        $resultCode = $result->$responseNode->code;
        if (!empty($resultCode) && $resultCode == 10000) {
            echo "成功";
        } else {
            echo "失败";
        }
    }

}
